//
//  HQBaseTabBarController.m
//  WaGuaMall
//
//  Created by 黄华强 on 2019/3/21.
//  Copyright © 2019 黄华强. All rights reserved.
//

#import "HQBaseTabBarController.h"

#import "HQHomeController.h"
#import "HQSecondController.h"
#import "HQThirdController.h"
#import "hqFourthController.h"
#import "HQMeController.h"


@interface HQBaseTabBarController ()<UITabBarControllerDelegate>

@end

@implementation HQBaseTabBarController

#pragma mark - 视图生命周期相关方法

- (void)viewDidLoad {
    [super viewDidLoad];
        
    self.delegate = self;
    
    //添加子控制器
    [self addChildController];
    
    //添加无网络指示标签
  //  [[HQNetRequestTool sharedHQNetRequestTool] netWorkReachabilityWithURLString:@"https://www.baidu.com"];
}

- (void)addChildController {
    
    NSString *homeString = @"首页";
    NSString *secondString = @"第二";
    NSString *thirdString = @"第三";
    NSString *fourthString = @"第四";
    NSString *meString = @"我的";
    
    
    HQBaseNaviController *homeNavi = [[HQBaseNaviController alloc] initWithRootViewController:[HQHomeController new]];
    
    homeNavi.title = homeString;
    homeNavi.tabBarItem.image = [[UIImage imageNamed:homeString] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeNavi.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_",homeString]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    
    HQBaseNaviController *secondNavi = [[HQBaseNaviController alloc] initWithRootViewController:[HQSecondController new]];
    
    secondNavi.title = secondString;
    secondNavi.tabBarItem.image = [[UIImage imageNamed:secondString] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    secondNavi.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_",secondString]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    HQBaseNaviController *thirdNavi = [[HQBaseNaviController alloc] initWithRootViewController:[HQThirdController new]];
    
    thirdNavi.title = thirdString;
    thirdNavi.tabBarItem.image = [[UIImage imageNamed:thirdString] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    thirdNavi.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_",thirdString]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    HQBaseNaviController *fourthNavi = [[HQBaseNaviController alloc] initWithRootViewController:[HQFourthController new]];
    
    fourthNavi.title = fourthString;
    fourthNavi.tabBarItem.image = [[UIImage imageNamed:fourthString] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    fourthNavi.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_",fourthString]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    HQBaseNaviController *meNavi = [[HQBaseNaviController alloc] initWithRootViewController:[HQMeController new]];
    
    meNavi.title = meString;
    meNavi.tabBarItem.image = [[UIImage imageNamed:meString] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    meNavi.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_",meString]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.viewControllers = @[homeNavi,secondNavi,thirdNavi,fourthNavi,meNavi];
    self.tabBar.tintColor = MAINTITLECOLOR;
    self.tabBar.translucent = NO;
    self.tabBar.clipsToBounds = YES;
    
}



#pragma mark - tabBar代理方法

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    if (viewController == tabBarController.viewControllers[0]) {
        
        return YES;
        
    } else if (viewController == tabBarController.viewControllers[1]) {
        
        return YES;
    } else if (viewController == tabBarController.viewControllers[2]) {
        
        return YES;
    } else {
        
        return YES;
    }
    
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    
}


@end
